<template>
  <div id="routewechatticket">
    <img src="../assets/images/anyloading.gif" class="logo" style="height:180px;">
  </div>
</template>

<script>
  export default{
    name: 'routewechatticket',
    components: {
    },
    data () {
      return {
        priasePath: sessionStorage.getItem('praisePath') || ''
      }
    },
    created: function () {
      // sessionStorage.clear()
      // localStorage.clear()
      // this.delCookie('openid')
      // this.delCookie('islogin')
      // this.delCookie('buycarlist')
      // 获取会员卡号
      this.$axios.post(this.apidomain + '/api/card/getWxCardId/' + this.getCookie('appid'), {
        cardType: 'MEMBER_CARD'
      })
      .then((response) => {
        const timestamp = Date.parse(new Date()) / 1000
        const nonceStr = Math.random().toString(36).substr(2)
        this.getObjDetail(this.apidomain + '/api/wechat/mp/getCardApiTicket/' + this.getCookie('appid'))
        .then((data) => {
          const noncearr = [timestamp, response.data.data.cardId, data.data, nonceStr]
          noncearr.sort()
          const signature = this.$jssha(noncearr.join(''))
          this.$wechat.ready(() => {
            this.$wechat.addCard({
              cardList: [{
                cardId: response.data.data.cardId,
                cardExt: '{"timestamp": "' + timestamp + '", "nonce_str": "' + nonceStr + '", "signature": "' + signature + '"}'
              }],
              success: (res) => {
                console.log(res)
                window.WeixinJSBridge.invoke('closeWindow')
                this.routeto('usersetting')
              },
              cancel: (error) => {
                console.log(error)
                window.WeixinJSBridge.invoke('closeWindow')
              }
            })
            window.WeixinJSBridge.invoke('closeWindow')
          })
        }, () => {})
      })
    },
    methods: {
    }
  }
</script>
<style lang="less">
#routewechatticket {
  width: 100%;
  height: 100%;
  text-align: center;
  position: fixed;
  top: 50%;
  img {
    margin-top: -90px;
  }
}
</style>
